package com.zhuoshi.controller;

import java.util.List;
import java.util.UUID;

import javax.xml.stream.events.Namespace;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhuoshi.bean.WdHtProject;
import com.zhuoshi.service.WdHtProjectService;

@Controller()
public class WdHtProjectController {

	@Autowired
	private WdHtProjectService wdHtProjectSerrvice;

	/**
	 * 查询以及模糊查询已经存在的项目
	 */
	@RequestMapping("/project/list")
	public String list(Model model, WdHtProject wdHtProject) {
		// 引入分页查询，使用PageHelper分页功能
		// 在查询之前传入当前页，然后多少记录
		PageHelper.startPage(1, 5);
		// startPage后紧跟的这个查询就是分页查询
		List<WdHtProject> list = wdHtProjectSerrvice.getAll(wdHtProject);
		// 使用PageInfo包装查询结果，只需要将pageInfo交给页面就可以
		PageInfo<WdHtProject> pageInfo = new PageInfo<>(list);
		// pageINfo封装了分页的详细信息，也可以指定连续显示的页数
		model.addAttribute("pageInfo", pageInfo);
		return "project_list";
	}

	/**
	 * 跳转到添加界面
	 */
	@RequestMapping("/project/toAdd")
	public String toAdd() {
		return "project_add";
	}

	/**
	 * 添加一个的功能
	 */
	@RequestMapping("/project/add")
	public String add(WdHtProject wdHtProject) {
		//设置uuid
		wdHtProject.setProjectId(UUID.randomUUID().toString());
		wdHtProjectSerrvice.add(wdHtProject);
		return "redirect:/project/list.do";
	}
	/**
	 * 删除一个的功能
	 */
	@RequestMapping("/project/del")
	public String del(String projectId) {
		//设置uuid
		wdHtProjectSerrvice.delOne(projectId);
		return "redirect:/project/list.do";
	}
	
	/**
	 * 查询一个的功能
	 */
	@RequestMapping("/project/toupdate")
	public String toupdate(String projectId,Model model) {
		//设置uuid
		WdHtProject bean = wdHtProjectSerrvice.selectOne(projectId);
		model.addAttribute("bean",bean);
		return "project_update";
	}
	
	
	/**
	 * 更新一个的功能
	 */
	@RequestMapping("/project/update")
	public String update(WdHtProject wdHtProject,Model model) {
		//设置uuid
	    int upOne = wdHtProjectSerrvice.upOne(wdHtProject);
	    
		return "redirect:/project/list.do";
	}
	
}
